Skip to content

Conversation

@Flamefire
Copy link
Member

When the goal for a ware becomes unreachable while it is carried into a harbor
RecalcRoute will call FindRouteToWarehouse.
Usually the selected warehouse will be the harbor as it is trivially the closest.
However when the harbor does not accept this ware type another one might be chosen
and the ware needs to be moved out instead of stored.

But FindRouteToWarehouse does NOT set next_dir while the ware is carried even when
called from RecalcRoute where the caller assumes it is set.
Changing this causes replays to go async, so work around it by calling RecalcRoute again
which now succeeds as it reached the goal in the previous call.

This bug also affects WantInBuilding which also calls RecalcRoute assuming it does so in all cases.

Fixes #1843

The test case was a bit tricky to write and I added the case where no goal is possible in which case the ware should be accepted in the ware house anyway.

@stefson
Copy link
Contributor

stefson commented Jan 5, 2026

it seems as if I drove the logistics into an interesting corner case? :-)

The check `GetGoal() != GetLocation()` is always met because
the location is the flag and the goal is NULL if it was destroyed while
the ware is being carried out.
When the goal for a ware becomes unreachable while it is carried into a harbor
`RecalcRoute` will call `FindRouteToWarehouse`.
Usually the selected warehouse will be the harbor as it is trivially the closest.
However when the harbor does not accept this ware type another one might be chosen
and the ware needs to be moved out instead of stored.

But `FindRouteToWarehouse` does NOT set `next_dir` while the ware is carried even when
called from `RecalcRoute` where the caller assumes it is set.
Changing this causes replays to go async, so work around it by calling `RecalcRoute` again
which now succeeds as it reached the goal in the previous call.

This bug also affects `WantInBuilding` which also calls `RecalcRoute` assuming it does so in all cases.

Fixes Return-To-The-Roots#1843
Flow86
Flow86 previously approved these changes Jan 12, 2026
@Flamefire Flamefire requested a review from Flow86 January 13, 2026 07:57
@Flamefire
Copy link
Member Author

it seems as if I drove the logistics into an interesting corner case? :-)

Yeah, it's a timing issue and hence difficult to reproduce in "normal" circumstances so I cheated a bit for the test case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unknown crash

3 participants